Oyuna 2 reklam ekleme
20.09.2016 - 03:41
Mrb. arkadaşlar oyun içerisine hem baner hemde geçiş reklamı eklemek istiyorum. Aşağıdaki kodlarda baner reklam çalışıyor ancak geçiş reklam nasıl ekleyebilirim. Yardımcı olabilirseniz sevinirim.
ads.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="banner_id"> ca-app-pub-xxxxxxxxxxxxxxxxxx</string>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.play"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22" />
<!-- Used to request banner and interstitial ads. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Used to avoid sending an ad request if there is no connectivity. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.AndroidLauncher"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
</manifest>
AndroidLauncher.java
package com.codecanyon.xxxx;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.randombot.swaptheglyph.SwapTheGlyph;
import com.randombot.swaptheglyph.utils.Resolver;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class AndroidLauncher extends AndroidApplication implements Resolver {
private static final boolean ADS = true;
private AdView adView;
private String facebook;
private String twitter;
private String market;
private String randombot;
private String appName;
private String googlePlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.facebook = getString(R.string.facebook);
this.twitter = getString(R.string.twitter);
this.market = getString(R.string.market);
this.randombot = getString(R.string.randombot);
this.appName = getString(R.string.app_name);
this.googlePlay = getString(R.string.google_play);
// Create the libgdx View
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.hideStatusBar = true;
cfg.useAccelerometer = false;
cfg.useCompass = false;
cfg.useImmersiveMode = true;
cfg.useWakelock = false;
if (ADS) {
// Create the layout
RelativeLayout layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow()
.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
View gameView = initializeForView(new SwapTheGlyph(this), cfg);
this.adView = new AdView(this);
this.adView.setAdUnitId(getString(R.string.banner_id));
this.adView.setAdSize(AdSize.SMART_BANNER);
this.adView.loadAd(new AdRequest.Builder().build());
/**
* Invoking { requestWindowFeature(Window.FEATURE_NO_TITLE); } will
* make the add view not to be shown until the next event (updating
* the ad every 60 seconds or pause/resume) By calling
* setBackgroundColor we force the add to show itself as soon as
* it's loaded.
*/
this.adView.setBackgroundColor(Color.TRANSPARENT);
// Add the libgdx view
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(this.adView, adParams);
// Hook it all up
setContentView(layout);
} else {
initialize(new SwapTheGlyph(this), cfg);
}
}
@Override
protected void onPause() {
if (ADS) {
adView.pause();
}
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
if (ADS) {
adView.resume();
}
}
@Override
protected void onDestroy() {
if (ADS) {
adView.destroy();
}
super.onDestroy();
}
@Override
public void onBackPressed() {
}
@Override
public void resolve(int which, int arg) {
switch (which) {
case RANKING: {
break;
}
case SHARE: {
Intent sharingIntent = new Intent(
android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Let's play " + this.appName + "!\n"
+ this.googlePlay;
sharingIntent
.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
break;
}
case SHOW_URI: {
String res = "";
switch (arg) {
case SHOW_URI_FACEBOOK:
res = this.facebook;
break;
case SHOW_URI_TWITTER:
res = this.twitter;
break;
case SHOW_URI_MARKET:
res = this.market;
break;
case SHOW_URI_RANDOMBOT:
res = this.randombot;
break;
}
Uri myUri = Uri.parse(res);
Intent intent = new Intent(Intent.ACTION_VIEW, myUri);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);
break;
}
default:
break;
}
}
}
13
Görüntülenme
0 Beğeni